<%-- 
    Document   : SearchResult
    Created on : Mar 8, 2012, 3:09:36 AM
    Author     : maconcon
--%>
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <%
            response.setHeader("Pragma","no-cache");
            response.setHeader("Cache-Control","no-store");
            response.setHeader("Expires","0");
            response.setDateHeader("Expires",-1);
        %>
        
         <%
        if(session.getAttribute("admin")== null){
            response.sendRedirect("adminlogin1234.jsp");
            }

               else{
        %>
        
    
    </head>
    <body>
       <%
  // String name = request.getParameter("search");
  // session.setAttribute( "search", name );
%>
      <%
    try {

String connectionURL = "jdbc:mysql://localhost:3306/databasefoobar";
// declare a connection by using Connection interface
Connection connection = null;
/* declare object of Statement interface that is used for executing sql
statements. */
Statement statement = null;
// declare a resultset that uses as a table for output data from tha table.
ResultSet rs = null;
ResultSet rs2= null;
// Load JBBC driver "com.mysql.jdbc.Driver"
Class.forName("com.mysql.jdbc.Driver").newInstance();
/* Create a connection by using getConnection() method that takes parameters
of string type connection url, user name and password to connect to database.*/
connection = DriverManager.getConnection(connectionURL, "root", "123456");
/* createStatement() is used for create statement object that is used for
sending sql statements to the specified database. */
statement = connection.createStatement();
 PreparedStatement pstmt = connection.prepareStatement("SELECT * FROM customer ");
//pstmt.setString(1, "%"+name+"%");

 rs = pstmt.executeQuery();
//String id=session.getAttribute("id").toString();
int id=Integer.parseInt(session.getAttribute("id").toString());
// sql query to retrieve values from the secified table.
%>
 <a href="adminprofile.jsp"> View Profile </a>
         <a href="adminaddprod.jsp"> Add Product</a>
         <a href="adminaddmanager.jsp"> Add Manager </a>
          <a href="admincustomerlist.jsp"> Customer List </a>
             <a href="adminmanagerlist.jsp"> Manager List </a>
                       <a href="admineditproduct.jsp"> Product List </a>
         <a href="AdminLogoutServlet"> Logout </a>s
         <Br><Br>
<a href="ShowCart.jsp">Show Cart</a><br> 
 <form action="SearchResult.jsp" method="POST">    
            Search: <input type="text" name="search" /><input type="submit" value="Search" />
        </form><br>
 

 <TABLE BORDER="1">
            <TR>
            
              
                <TH>username</TH>
                <TH>status</TH>
                <th>update</th>
             
            </TR>
            <% while(rs.next()){ %>
            <form action="StatusServlet" method="POST">
            <TR>
                <input type="hidden" name="username"  value=<%=rs.getString("username")%> />
                  <input type="hidden" name="customerid"  value=<%=rs.getString("customerid")%> />
                <TD> <%= rs.getString("username") %></td>
                <TD> 
                    <%
                        if (rs.getString("status").equals("1")) {
                    %>
                    <select name="status"> <option value="1" >Active</option>
                        <option value="0">Deactivate</option>
                    </select>

                    <% }else{%>
                     <select name="status"> <option value="0">Deactivate</option>
                        <option value="1">Activate</option>
                    </select>
                <%}%>
                </TD>
                <td>   <input type="hidden" name="adminid"  value=<%=id%> />
                    <input type="submit" value="Update" />  
                    
                    </form>     

                </td>

            </TR>
            <% }%>
 </TABLE>

<%

// close all the connections.
rs.close();
statement.close();
connection.close();
} catch (Exception ex) {
%>
</font>
<font size="+3" color="red"></b>
<%
out.println("Unable to connect to database.");
}
%> 
        
    </body>
    <%
    }
    %>
</html>
